var beanstalkc = require('./beanstalk_client');
var randomstring = require("randomstring");

var server = '192.168.1.10:11300'
var start = Date.now()
var total = 0

var TEST_STRING_LEN = 100


beanstalkc.connect(server, function(err, conn) {
	if(err){
		console.log(`connect error ${err}`)
		return;
	}
	var TEST_STRING = randomstring.generate(TEST_STRING_LEN,true);

	var onCall = function(err,job_id,data) {
		total = total+1

		
		if(err){
			console.log(`call error ${err}`);
		}else{
			console.log(`oncall:${job_id} ${data}`);
		}
		
		
		if(total>=10000){
			console.log(`run finish total ${total} cost ${Date.now() - start} ms`)
			return
		}
		
		var job_data = randomstring.generate(TEST_STRING_LEN,true);
		conn.call(0, 5, 3, job_data,onCall);
	}

	var job_data = randomstring.generate(TEST_STRING_LEN,true);
	conn.call(0, 5, 3, job_data,onCall);

});

